using Microsoft.AspNetCore.Mvc;
using ZR.Model.BaseManage.Dto;
using ZR.Model.BaseManage;
using ZR.Service.BaseManage.IBaseManageService;
using ZR.Admin.WebApi.Filters;

//创建时间：2025-04-20
namespace ZR.Admin.WebApi.Controllers.BaseManage
{
    /// <summary>
    /// 客户信息
    /// </summary>
    [Verify]
    [Route("BaseManage/BaseCustom")]
    public class BaseCustomController : BaseController
    {
        /// <summary>
        /// 客户信息接口
        /// </summary>
        private readonly IBaseCustomService _BaseCustomService;

        public BaseCustomController(IBaseCustomService BaseCustomService)
        {
            _BaseCustomService = BaseCustomService;
        }

        /// <summary>
        /// 查询客户信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "base:custom:list")]
        public IActionResult PageBaseCustom([FromQuery] BaseCustomQueryDto parm)
        {
            var response = _BaseCustomService.GetPageList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询客户信息详情
        /// </summary>
        /// <param name="CostumId"></param>
        /// <returns></returns>
        [HttpGet("{CostumId}")]
        [ActionPermissionFilter(Permission = "base:custom:query")]
        public IActionResult GetBaseCustom(string CostumId)
        {
            var response = _BaseCustomService.GetInfo(CostumId);
            
            var info = response.Adapt<BaseCustomDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "base:custom:add")]
        [Log(Title = "客户信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddBaseCustom([FromBody] BaseCustomDto parm)
        {
            var modal = parm.Adapt<BaseCustom>().ToCreate(HttpContext);

            var response = _BaseCustomService.AddBaseCustom(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新客户信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "base:custom:edit")]
        [Log(Title = "客户信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateBaseCustom([FromBody] BaseCustomDto parm)
        {
            var modal = parm.Adapt<BaseCustom>().ToUpdate(HttpContext);
            var response = _BaseCustomService.UpdateBaseCustom(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除客户信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "base:custom:delete")]
        [Log(Title = "客户信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteBaseCustom([FromBody] string[] ids)
        {
            return ToResponse(_BaseCustomService.Delete(ids));
        }

    }
}